/**
 * ipassbook 0.6.0
 * Copyright (C)2009 wateray and contributors
 * wateray@gmail.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package com.wateray.ipassbook.ui.widget;

import javax.swing.JTable;

import com.wateray.ipassbook.domain.Entity;
import com.wateray.ipassbook.domain.form.ReceiptForm;
import com.wateray.ipassbook.ui.model.AbstractPassbookTableModel;
import com.wateray.ipassbook.ui.model.ReceiptTabelModel;

/**
 * PassbookTable must install AbstractPassbookTableModel.
 * 
 * @author wateray
 * @create 2009-6-6
 */
public class PassbookTable extends JTable {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	/** Model. */
	private AbstractPassbookTableModel model;

	public PassbookTable() {
		super();
	}

	public PassbookTable(AbstractPassbookTableModel dm) {
		super(dm);
	}

	/**
	 * @return this.convertRowIndexToModel(this.getSelectedRow()).
	 * */
	public int getSelectedIndex() {
		int index = this.getSelectedRow();
		if (index != -1) {
			index = this.convertRowIndexToModel(this.getSelectedRow());
		}
		return index;
	}
	
	/**
	 * @return model.getRowObject(selectedIndex).
	 * */
	public Entity getSelectedObject() {
		if(getSelectedIndex() == -1)
			return null;
		
		return  ((ReceiptTabelModel) this.getModel())
				.getRowObject(getSelectedIndex());
	}

}
